package com.cebbank.sz.cebtemplate.config;
//
//import com.baomidou.mybatisplus.core.MybatisConfiguration;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import com.cebbank.sz.cebtemplate.config.datasource.MultipleDataSource;
//import com.cebbank.sz.cebtemplate.constant.DataSourceEnum;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.type.JdbcType;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据源配置
 * @author sucz
 * @create 2019/12/16 10:54
 */
@Configuration
@MapperScan("com.cebbank.sz.cebtemplate.dao.*")
public class MyBatisPlusConfig {
//
//    @Value("${mybatis-plus.mapperLocations}")
//    private String mapperLocation;
//
//    /**
//     * 分页插件，自动识别数据库类型
//     * @return
//     */
//    @Bean
//    public PaginationInterceptor paginationInterceptor() {
//        return new PaginationInterceptor();
//    }
//
//    /**
//     * 平台库
//     * @return
//     */
//    @Bean(name = "dbkj")
//    @ConfigurationProperties(prefix = "spring.datasource.druid.dbkj")
//    public DataSource dbkj() {
//        return DataSourceBuilder.create().build();
//    }
//
//    /**
//     * 赞华库
//     * @return
//     */
//    @Bean(name = "dbzh")
//    @ConfigurationProperties(prefix = "spring.datasource.druid.dbzh")
//    public DataSource dbzh() {
//        return DataSourceBuilder.create().build();
//    }
//
//    /**
//     * 贯众库
//     * @return
//     */
//    @Bean(name = "dbgz")
//    @ConfigurationProperties(prefix = "spring.datasource.druid.dbgz")
//    public DataSource dbgz() {
//        return DataSourceBuilder.create().build();
//    }
//
//    /**
//     * 动态数据源配置
//     * @param dbkj
////     * @param dbzh
////     * @param dbgz
//     * @return
//     */
//    @Bean
//    @Primary
//    public DataSource multipleDataSource(@Qualifier("dbkj") DataSource dbkj
//                                         ,@Qualifier("dbzh") DataSource dbzh, @Qualifier("dbgz") DataSource dbgz
//    ) {
//        MultipleDataSource multipleDataSource = new MultipleDataSource();
//        Map<Object, Object> targetDataSources = new HashMap<>(16);
//        targetDataSources.put(DataSourceEnum.DBKJ.getValue(), dbkj);
//        targetDataSources.put(DataSourceEnum.DBZH.getValue(), dbzh);
//        targetDataSources.put(DataSourceEnum.DBGZ.getValue(), dbgz);
//        // 添加数据源
//        multipleDataSource.setTargetDataSources(targetDataSources);
//        // 设置默认数据源
//        multipleDataSource.setDefaultTargetDataSource(dbkj);
//        return multipleDataSource;
//    }
//
//    @Bean("sqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory() throws Exception {
//        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
//        sqlSessionFactory.setDataSource(multipleDataSource(dbkj()
//                , dbzh(), dbgz()
//        ));
//        sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocation));
//
//        MybatisConfiguration configuration = new MybatisConfiguration();
//        configuration.setJdbcTypeForNull(JdbcType.NULL);
//        configuration.setMapUnderscoreToCamelCase(true);
//        configuration.setCacheEnabled(false);
//
//        sqlSessionFactory.setConfiguration(configuration);
//
//        return sqlSessionFactory.getObject();
//    }
//
    @Bean
    public IKeyGenerator keyGenerator() {
        return new OracleKeyGenerator();
    }


}
